

var getDate = function(){
	var currentTime = new Date();
	this.cdate = new Date().getDate()
	this.y = currentTime.getFullYear();
	this.m = (currentTime.getMonth())+1;
	this.d = currentTime.getDate();
	//获取当前月份
	this.getCurrentMonth = function(){
		var t = this.y+'/'+this.m
		return t;
	}
	//设置当前月份
	this.setCurrentMonth = function(y,m){
		this.y = y
		this.m = m
	}
	return this;
};

//获取月份数据
getDate.prototype.constructor = getDate;
getDate.prototype.getData = function(y, m, obj){
	var m = m < 10 ? ('0' + m) : m;
	
	var currentData = new Date(y+'/'+m+'/1');
	var currentDay = currentData.getDay();
	var currentLength = (new Date(y, m, 0)).getDate();
	
	var data = [];	//指定月份的数据
	for(var i=0;i<currentLength;i++){
		var week = (currentDay+i)%7;
		var day = i+1;
		var itemDay = {}
			itemDay.week = week,
			itemDay.day = day
		
		var cday = day < 10 ? ('0' + day) : day;
		var currentDayData = y + '/' + m + '/' + cday;
		if(obj && obj.length && obj.length > 0){
			var ci = obj.indexOf(currentDayData);
			if(ci != -1){
				itemDay.sign = 1;	//已签到
			}
		}
		if(this.cdate === day){
			itemDay.current = 1;
		}
		data.push(itemDay);
	}
	return data;
}
//本月数据
getDate.prototype.getNowDate = function(obj){
	var currentTime = new Date();
	var y = currentTime.getFullYear();
	var m = (currentTime.getMonth())+1;
	
	this.setCurrentMonth(y, m);
	var data = this.getData(y, m, obj);
	return data;
}
//上月数据
getDate.prototype.getPrevDate = function(obj){
	var currentMonth = (this.getCurrentMonth()) + '/1';
	var prevDate = (new Date(currentMonth)).getTime() - 24*60*60*1000;
	prevDate = new Date(prevDate)
	
	var y = prevDate.getFullYear();
	var m = (prevDate.getMonth())+1;
	
	this.setCurrentMonth(y, m);
	var data = this.getData(y, m, obj);
	return data;
}
//下月数据
getDate.prototype.getNextDate = function(obj){
	var currentMonth = (this.getCurrentMonth()) + '/1';
	
	var nextDate = (new Date(currentMonth)).getTime() + 33*24*60*60*1000;
	nextDate = new Date(nextDate)
	
	var y = nextDate.getFullYear();
	var m = (nextDate.getMonth())+1;
	
	this.setCurrentMonth(y, m);
	var data = this.getData(y, m, obj);
	return data;
}
export default getDate;


















